import { action, makeObservable, observable } from "mobx";
import { Bone } from "../animation/models/Bone";
import { emitter } from "../eventEmitter";

export const enum PropertyType {
    Bone = "bone",
    Slot = "slot",
    Armature = "armature",
}

export type BoneData = {
    length: number;
    alpha: number;
    name: string;
    parent: string;
}

export type SlotData = {
    name: string;
}

export class PropertyStore {
    type: PropertyType = PropertyType.Bone;
    boneData: BoneData = {
        length: 0.0,
        alpha: 1.0,
        name: "",
        parent: "",
    };

    slotData: SlotData = {
        name: '',
    };

    constructor() {
        makeObservable(this, {
            type: observable,
            boneData: observable,
            slotData: observable,
            setBoneData: action,
            setType: action,
            setBoneLength: action,
        });
    }

    setType(type: PropertyType) {
        this.type = type;
    }

    setBoneData(bone: Bone) {
        this.boneData.length = +bone.length.toFixed(0);
        this.boneData.alpha = bone.alpha;
        this.boneData.name = bone.name;
        this.boneData.parent = bone.parent;
    }

    setBoneLength(length: number) {
        this.boneData.length = length;
        emitter.emit("updateBoneData", this.boneData);
    }
}

export default new PropertyStore();
